package com.example.shiwu.service;

import android.content.Context;

import com.example.shiwu.db.dao.BoxSixDao;
import com.example.shiwu.db.dao.base.BaseDaoFactory;
import com.example.shiwu.db.model.BoxOne;
import com.example.shiwu.db.model.BoxSix;
import com.example.shiwu.manager.DatabaseHelper;

import java.util.ArrayList;
import java.util.List;

public class BoxSixService {

    private DatabaseHelper dbHelper;
    private BoxSixDao<BoxSix> BoxSixDao;
    private ArrayList<BoxSix> listBoxSix = null;

    private static final int PAGE_SIZE = 10;
    private static final int TOTAL_PAGE = 0;

    public BoxSixService() {
    }

    public BoxSixService(Context context) {
        dbHelper = new DatabaseHelper(context);
    }


    /**获取单个数据
     * @param BoxSix
     * @return
     */
    public List<BoxSix> getBoxSix(BoxSix BoxSix) {
        BoxSixDao = BaseDaoFactory.getInstance().createBaseDao(BoxSixDao.class, BoxSix.class);
        listBoxSix = new ArrayList<>();
        listBoxSix.addAll(BoxSixDao.query(BoxSix));
        return listBoxSix;
    }

    /**分页获取数据
     * @param BoxSix
     * @return
     */
    public List<BoxSix> getBoxSixList(BoxSix BoxSix,Integer startIndex,Integer limit) {
        BoxSixDao = BaseDaoFactory.getInstance().createBaseDao(BoxSixDao.class, BoxSix.class);
        listBoxSix = new ArrayList<>();
        listBoxSix.addAll(BoxSixDao.query(BoxSix,null,"create_time desc",null,startIndex,limit));
        return listBoxSix;
    }


    public boolean save(BoxSix BoxSix) {
        BoxSixDao = BaseDaoFactory.getInstance().createBaseDao(BoxSixDao.class, BoxSix.class);
        long size = BoxSixDao.insert(BoxSix);
        if(size >0 ){
            return true;
        }
        return false;
    }
    public boolean saveOrUpdata(BoxSix BoxSix) {
        BoxSixDao = BaseDaoFactory.getInstance().createBaseDao(BoxSixDao.class, BoxSix.class);
        BoxSix boxSix = new BoxSix();
        boxSix.setItemId(BoxSix.getItemId());
        List<BoxSix> lis =BoxSixDao.query(boxSix);
        Boolean bl = true;
        if(lis.size()>0){
            long size = BoxSixDao.update(BoxSix,new BoxSix());
            if(size >0 ){
                return bl;
            }
            bl = false;
        }else{
            long size = BoxSixDao.insert(BoxSix);
            if(size >0 ){
                return bl;
            }
            bl = false;
        }

        return bl;
    }

    public boolean updade(BoxSix BoxSix,BoxSix where) {
        long size = BoxSixDao.update(BoxSix,where);
        if(size >0 ){
            return true;
        }
        return false;
    }

    public Boolean delete(BoxSix boxSix) {
        int size = BoxSixDao.delete(boxSix);
        if(size >0 ){
            return true;
        }
        return false;
    }
}
